package cn.itcast.web.servlet;

import cn.itcast.domain.Req;
import cn.itcast.service.ReqService;
import cn.itcast.service.impl.ReqServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findReqByYidServlet")
public class FindReqsByYidServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置参数
        request.setCharacterEncoding("utf-8");
        //1获取id
        String id = request.getParameter("yid");
        //2调用service方法查询
        ReqService service=new ReqServiceImpl();
        List<Req> reqs= service.findReqsByYid(id);
        int size = reqs.size();
        if(size!=0){
            //2存入request域中
            request.setAttribute("reqs",reqs);
            request.setAttribute("uid",id);
            //3转发到Reqlist.jsp中
            request.getRequestDispatcher("/Reqlist.jsp").forward(request,response);
        }else{

            //2存入request域中
            request.setAttribute("reqs",reqs);
            request.setAttribute("uid",id);
            request.setAttribute("empty_msg","等待获取需求...");
            //3转发到Reqlist.jsp中
            request.getRequestDispatcher("/Reqlist.jsp").forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
